﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Time.cs" company="">
//   
// </copyright>
// <summary>
//   The time.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.Diagnostics;

namespace Systemathics.FrameWork
{
    public sealed class Time
    {
        private static DateTime DateInit;

        private static double Frequency = Double.NaN;
        private static double TickInit = Double.NaN;

        public static DateTime Now
        {
            get
            {
                double current_tick = Stopwatch.GetTimestamp(); 
                if (Double.IsNaN(TickInit))
                {
                    DateInit = DateTime.Now;
                    TickInit = current_tick;
                }

                if (Double.IsNaN(Frequency))
                {
                    Frequency = Stopwatch.Frequency;
                }
                 
                double diff = current_tick - TickInit;
                return new DateTime(DateInit.Ticks + (long) (1000.0*TimeSpan.TicksPerMillisecond*diff/Frequency));
            }
        }
    }
}